<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Default Variable Handling</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="tips.html" title="Chapter 21. Tips &amp; Tricks">
<link rel="prev" href="tips.html" title="Chapter 21. Tips &amp; Tricks">
<link rel="next" href="tips.passing.vars.html" title="Passing variable title to header template">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Default Variable Handling</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="tips.html">Prev</a> </td>
<th width="60%" align="center">Chapter 21. Tips &amp; Tricks</th>
<td width="20%" align="right"> <a accesskey="n" href="tips.passing.vars.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Default Variable Handling">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="tips.default.var.handling"></a>Default Variable Handling</h2></div></div></div>
<p>
    If a variable is used frequently throughout your templates, applying
    the <a class="link" href="language.modifier.default.html" title="default"><code class="varname">default</code>
    </a> modifier every time it is mentioned can get a bit ugly. You
    can remedy this by assigning the variable its default value with the
    <a class="link" href="language.function.assign.html" title="{assign}"><code class="varname">{assign}</code></a>
    function.
   </p>
<div class="example">
<a name="id468682"></a><p class="title"><b>Example 21.2. Assigning a template variable its default value</b></p>
<div class="example-contents"><pre class="programlisting">

{* do this somewhere at the top of your template *}
{assign var='title' value=$title|default:'no title'}

{* if $title was empty, it now contains the value "no title" when you use it *}
{$title}

    </pre></div>
</div>
<br class="example-break"><p>
    See also
    <a class="link" href="language.modifier.default.html" title="default"><code class="varname">default</code></a>
     modifier and <a class="link" href="tips.html#tips.blank.var.handling" title="Blank Variable Handling">blank variable handling</a>.
   </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="tips.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="tips.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="tips.passing.vars.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 21. Tips &amp; Tricks </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Passing variable title to header template</td>
</tr>
</table>
</div>
</body>
</html>
